class BlackDeathMelee extends BlackDeathWeapon
        abstract;

var float weaponLength;
var float MomentumScale;//Scalar for how much momentum to put onto an enemy when attacked.
var name TipSocket;//name of the socket to end our wepon trace at
var name BaseSocket;//name of the socket to begin our trace at

var float HitResistenceScaler; //Scaler to apply to pawn's animations on when this weapon scores a hit.
var float HitResistenceDuration; //Amount of time to decrease speed on impact. Should be very short, under 0.5.
var float HitResistenceDurationEaseIn;
var float HitResistenceDurationEaseOut;

var array<Pawn> hitEnemies;
var const float ATTACK_COLLISION_CHECK_RATE;

	simulated function Activate()
	{
		local vector Start, End;
		`log(Self@": activitvated!");
		super.Activate();
		SkeletalMeshComponent(Mesh).GetSocketWorldLocationAndRotation(TipSocket, End);
		SkeletalMeshComponent(Mesh).GetSocketWorldLocationAndRotation(BaseSocket, Start);
		weaponLength = VSize(End - Start);
	}
	
	function CallAttack()
	{
		hitEnemies.Remove(0, hitEnemies.Length); //empty the array
		tryAttack();
		SetTimer(ATTACK_COLLISION_CHECK_RATE, true, 'tryAttack');
	}
	
	simulated function EndSwing()
	{
		ClearTimer('tryAttack');
		super.EndSwing();
	}
	
	function tryAttack()
	{
		local vector Start, End, HitLocation, HitNormal;
		local Actor HitActor;

		
		//Maybe do fast traces to make this more efficient, instead of doing non-stop traces. On the other hand, that would mean two traces per hit when passing though an enemy.
		SkeletalMeshComponent(Mesh).GetSocketWorldLocationAndRotation(TipSocket, End);
		SkeletalMeshComponent(Mesh).GetSocketWorldLocationAndRotation(BaseSocket, Start);
		HitActor = Trace(HitLocation, HitNormal, end, start, true,,, TRACEFLAG_Bullet);
		if ((VSize(HitLocation - Start) < weaponLength)&&(BlackDeathPawn(HitActor) != None) )
		{
			if( hitEnemies.Find(HitActor) == -1 ) //only strike if we haven't already hit.
			{
				doAttack(Pawn(HitActor), HitLocation);
				hitEnemies.AddItem(Pawn(HitActor));
			}
		}
	}
	
	simulated function doAttack(Pawn AttackedPawn, Vector HitLocation)//Do the actual hit to the thing
	{
		local vector X, Y, Z, Momentum;
		local float Damage;
		local BlackDeathHeroPawn AttackingHero;

		WorldInfo.Game.Broadcast(none, "doing actual attack");
		GetAxes(Instigator.rotation, X, Y, Z);
		Momentum = MomentumScale * X /*+ MomentumScale * Y + MomentumScale * Z*/;//Find the player's rotation in vector form and multiple it by the force of the attack
		Damage = WeaponDamage;

		AttackingHero = BlackDeathHeroPawn(Instigator);
		if(AttackingHero != none)
		{
			Momentum *= AttackingHero.momentumModifier;
			Damage *= AttackingHero.damageModifier;
			AttackingHero.notifyAttackHit(self);
		}

		if(currentfiremode == 0)
		{
			AttackedPawn.TakeDamage(Damage, Instigator.Controller, HitLocation, Momentum, class'DmgType_Crushed');
		}
		if(currentfiremode == 1)
		{
			AttackedPawn.TakeDamage(HeavyWeaponDamage, Instigator.Controller, HitLocation, Momentum, class'DmgType_Crushed');
		}
		BlackDeathPawn(Instigator).setPawnAminScale(HitResistenceScaler, HitResistenceDuration, HitResistenceDurationEaseIn, HitResistenceDurationEaseOut );
	}

	simulated function bool HasAnyAmmo()
	{
		return true;//Weapon always has ammo
	}

	function ConsumeAmmo( byte FireModeNum )
	{
		//Melee weapons do not consume ammo
	}
	
	function int AddAmmo(int Amount)
	{
		//Melee weapons cannot get ammo
	}
	
	simulated function StartFire(Byte FireModeNum)
	{
		if(FireModeNum == 0)
		{
			SetLightAttackAnimBlend();
		}
		else
		{
			SetHeavyAttackAnimBlend();
		}
		`log(self@": start fire called");
		super.StartFire(FireModeNum);
	}
	
	function SetLightAttackAnimBlend()
	{
		//SwingVar.SetBlendTarget(0.0,0.0);
	}
	function SetHeavyAttackAnimBlend()
	{
		//SwingVar.SetBlendTarget(1.0,0.0);
	}
	
	simulated function CustomFire()
	{
		local BlackDeathPawn BDP;
		BDP = BlackDeathPawn(instigator);
		if(BDP != none)
		{
			BDP.PlayWeaponSwing();
		}
	}

	simulated function bool ShouldRefire()
	{
		return false; //Never refire! -Reza
	}
	
DefaultProperties
{
	Begin Object Class=SkeletalMeshComponent Name=PickupMesh
		bOnlyOwnerSee=false
		CastShadow=false
		bForceDirectLightMap=true
		bCastDynamicShadow=false
		CollideActors=true
		BlockRigidBody=true
		MaxDrawDistance=6000
		bForceRefPose=1
		bUpdateSkelWhenNotRendered=false
		bIgnoreControllersWhenNotRendered=true
		bAcceptsStaticDecals=FALSE
		bAcceptsDynamicDecals=FALSE
		bAllowAmbientOcclusion=false
		SkeletalMesh=SkeletalMesh'BD_Weapon.Greatsword_Weapon'
	End Object
	DroppedPickupMesh=PickupMesh
	DroppedPickupClass=class'DroppedPickup'
	
	WeaponDamage = 10; //How much damage the wepon does
	HeavyWeaponDamage = 20;//How much damage the heavy fire mode does
	
	FiringStatesArray(0)=WeaponFiring
	FiringStatesArray(1)=WeaponFiring
	WeaponFireTypes(0)=EWFT_Custom
	WeaponFireTypes(1)=EWFT_Custom
	
	WeaponProjectiles(0)=none
	//WeaponProjectiles(1)=class'ThorwnMelee'
	
	EquipTime=+0.33
	PutDownTime=+0.33
	
	StaminaCost(0)=5
	StaminaCost(1)=10
	
	FireInterval(0)=1.0
	FireInterval(1)=1.0
	
	Spread(0)=0.0
	Spread(1)=0.0

	AIRating=1.0
	
	TipSocket = Tip_Socket
	BaseSocket = base_Socket

	HitResistenceScaler = 0;
	HitResistenceDuration = 0.08;
	HitResistenceDurationEaseIn = 0.0;
	HitResistenceDurationEaseOut = 0.05;
	
	hitEnemies = ()
	ATTACK_COLLISION_CHECK_RATE = 0.005
	
	
	Begin Object Class=SkeletalMeshComponent Name=WeaponMesh
		bOnlyOwnerSee=false
		CollideActors=false
		AlwaysLoadOnClient=true
		AlwaysLoadOnServer=true
		MaxDrawDistance=4000
		bForceRefPose=1
		bUpdateSkelWhenNotRendered=false
		bIgnoreControllersWhenNotRendered=true
		bOverrideAttachmentOwnerVisibility=true
		bAcceptsDynamicDecals=FALSE
		//Animations=MeshSequenceA
		CastShadow=true
		bCastDynamicShadow=true
		bAllowAmbientOcclusion=false
		//Translation=(Z=1)
		//Rotation=(Roll=-400)
		//Scale=0.9
	End Object
	Mesh=WeaponMesh
}